﻿using System;
using System.ComponentModel;

namespace HalconDotNet
{
	/// <summary>Represents an instance of a condition synchronization object.</summary>
	// Token: 0x0200002B RID: 43
	public class HCondition : HHandle
	{
		// Token: 0x060003C0 RID: 960 RVA: 0x0000883B File Offset: 0x00006A3B
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HCondition() : base(HHandleBase.UNDEF)
		{
		}

		// Token: 0x060003C1 RID: 961 RVA: 0x000165D9 File Offset: 0x000147D9
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HCondition(IntPtr handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x060003C2 RID: 962 RVA: 0x000165E8 File Offset: 0x000147E8
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HCondition(HHandle handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x060003C3 RID: 963 RVA: 0x000165F7 File Offset: 0x000147F7
		private void AssertSemType()
		{
			base.AssertSemType("condition");
		}

		// Token: 0x060003C4 RID: 964 RVA: 0x00016604 File Offset: 0x00014804
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HCondition obj)
		{
			obj = new HCondition(HHandleBase.UNDEF);
			return obj.Load(proc, parIndex, err);
		}

		// Token: 0x060003C5 RID: 965 RVA: 0x0001661C File Offset: 0x0001481C
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HCondition[] obj)
		{
			HTuple htuple;
			err = HTuple.LoadNew(proc, parIndex, err, out htuple);
			obj = new HCondition[htuple.Length];
			for (int i = 0; i < htuple.Length; i++)
			{
				obj[i] = new HCondition(HalconAPI.IsLegacyHandleMode() ? htuple[i].IP : htuple[i].H);
			}
			htuple.Dispose();
			return err;
		}

		/// <summary>
		///   Create a condition variable synchronization object.
		///   Modified instance represents: Condition synchronization object.
		/// </summary>
		/// <param name="attribName">Mutex attribute. Default: []</param>
		/// <param name="attribValue">Mutex attribute value. Default: []</param>
		// Token: 0x060003C6 RID: 966 RVA: 0x0001668C File Offset: 0x0001488C
		public HCondition(HTuple attribName, HTuple attribValue)
		{
			IntPtr proc = HalconAPI.PreCall(548);
			HalconAPI.Store(proc, 0, attribName);
			HalconAPI.Store(proc, 1, attribValue);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(attribName);
			HalconAPI.UnpinTuple(attribValue);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Create a condition variable synchronization object.
		///   Modified instance represents: Condition synchronization object.
		/// </summary>
		/// <param name="attribName">Mutex attribute. Default: []</param>
		/// <param name="attribValue">Mutex attribute value. Default: []</param>
		// Token: 0x060003C7 RID: 967 RVA: 0x000166EC File Offset: 0x000148EC
		public HCondition(string attribName, string attribValue)
		{
			IntPtr proc = HalconAPI.PreCall(548);
			HalconAPI.StoreS(proc, 0, attribName);
			HalconAPI.StoreS(proc, 1, attribValue);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Destroy a condition synchronization object.
		///   Instance represents: Condition synchronization object.
		/// </summary>
		// Token: 0x060003C8 RID: 968 RVA: 0x00016740 File Offset: 0x00014940
		public void ClearCondition()
		{
			IntPtr proc = HalconAPI.PreCall(543);
			base.Store(proc, 0);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Signal a condition synchronization object.
		///   Instance represents: Condition synchronization object.
		/// </summary>
		// Token: 0x060003C9 RID: 969 RVA: 0x00016774 File Offset: 0x00014974
		public void BroadcastCondition()
		{
			IntPtr proc = HalconAPI.PreCall(544);
			base.Store(proc, 0);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Signal a condition synchronization object.
		///   Instance represents: Condition synchronization object.
		/// </summary>
		// Token: 0x060003CA RID: 970 RVA: 0x000167A8 File Offset: 0x000149A8
		public void SignalCondition()
		{
			IntPtr proc = HalconAPI.PreCall(545);
			base.Store(proc, 0);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Bounded wait on the signal of a condition synchronization object.
		///   Instance represents: Condition synchronization object.
		/// </summary>
		/// <param name="mutexHandle">Mutex synchronization object.</param>
		/// <param name="timeout">Timeout in micro seconds.</param>
		// Token: 0x060003CB RID: 971 RVA: 0x000167DC File Offset: 0x000149DC
		public void TimedWaitCondition(HMutex mutexHandle, int timeout)
		{
			IntPtr proc = HalconAPI.PreCall(546);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, mutexHandle);
			HalconAPI.StoreI(proc, 2, timeout);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
			GC.KeepAlive(mutexHandle);
		}

		/// <summary>
		///   wait on the signal of a condition synchronization object.
		///   Instance represents: Condition synchronization object.
		/// </summary>
		/// <param name="mutexHandle">Mutex synchronization object.</param>
		// Token: 0x060003CC RID: 972 RVA: 0x00016828 File Offset: 0x00014A28
		public void WaitCondition(HMutex mutexHandle)
		{
			IntPtr proc = HalconAPI.PreCall(547);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, mutexHandle);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
			GC.KeepAlive(mutexHandle);
		}

		/// <summary>
		///   Create a condition variable synchronization object.
		///   Modified instance represents: Condition synchronization object.
		/// </summary>
		/// <param name="attribName">Mutex attribute. Default: []</param>
		/// <param name="attribValue">Mutex attribute value. Default: []</param>
		// Token: 0x060003CD RID: 973 RVA: 0x0001686C File Offset: 0x00014A6C
		public void CreateCondition(HTuple attribName, HTuple attribValue)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(548);
			HalconAPI.Store(proc, 0, attribName);
			HalconAPI.Store(proc, 1, attribValue);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(attribName);
			HalconAPI.UnpinTuple(attribValue);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Create a condition variable synchronization object.
		///   Modified instance represents: Condition synchronization object.
		/// </summary>
		/// <param name="attribName">Mutex attribute. Default: []</param>
		/// <param name="attribValue">Mutex attribute value. Default: []</param>
		// Token: 0x060003CE RID: 974 RVA: 0x000168CC File Offset: 0x00014ACC
		public void CreateCondition(string attribName, string attribValue)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(548);
			HalconAPI.StoreS(proc, 0, attribName);
			HalconAPI.StoreS(proc, 1, attribValue);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}
	}
}
